/**
 * Created by chengming on 18/5/27.
 * version 1.0
 */
const BaseJsonAdapter = require('../base/BaseJsonAdapter');
const ArticleHrefAdapter = require('../ArticleHrefAdapter');
const iconv = require("iconv-lite");
const vm = require('vm');
const request = require('request-promise');
const logger = require('../../conf/logger');
const querystring = require("querystring")
const cheerio = require('cheerio');
const urlTool = require('url');
const urldecode = require('urlencode')

/**
 * 港交所-股权披露
 * @type {module.Bjp2p}
 */
module.exports = class SCHKExnews extends ArticleHrefAdapter {


    parseHtml(html, linkRule) {
        //将解析后的内容加载进解析器
        let $ = cheerio.load(html);
        let contents = [];
        let that = this;
        let rangeText = '';
        let encoding = this.encoding;
        let list = {}
        $(this.linkRule).each(function () {
            let title = $(this).find('td').eq(2).text().trim();
            if (title === '上市法团名称') {

            } else {
              title = title + '(' + $(this).find('td').eq(0).text().trim() + ')';
              let href = $(this).find('td').eq(0).find('a');
              if (href.is('a') && href.attr('href')) {
                href = urlTool.resolve(that.requestUrl, href.attr('href'))
              } else {
                href = that.requestUrl
              }
              if (title.length != 0 || href.length != 0) {
                contents.push({
                  title: title,
                  href: href
                });
                rangeText += title + href;
              }

            }
        });
        return {
            rangeText: rangeText,
            contents: contents
        };
    }


}
